1 module core.stdc.stdlib; 2 public import core.stdc.stddef; 3 4 enum EXIT_SUCCESS = 0; 5 enum EXIT_FAILURE = 1; 6 enum RAND_MAX = 0x7fffffff; 7 8 9 alias _compare_fp_t = extern(C) int function(const(void*) a, const(void*) b); 10 11 version(WebAssembly) version = CustomRuntime; 12 version(PSVita) version = CustomRuntime; 13 14 version(CustomRuntime) 15 { 16 private alias nogc_free_t = @nogc nothrow void function(ubyte* ptr); 17 private alias nogc_malloc_t = @nogc nothrow ubyte[] function(size_t size, string file, size_t line); 18 private alias nogc_calloc_t = @nogc nothrow ubyte[] function(size_t size, size_t count, string file, size_t line); 19 private alias nogc_realloc_t = @nogc nothrow ubyte[] function(ubyte* ptr, size_t size, string file, size_t line); 20 static import rt.hooks; 21 22 @nogc nothrow 23 { 24 void free(void* ptr) 25 { 26 auto nogc_free = cast(nogc_free_t)&rt.hooks.free; 27 nogc_free(cast(ubyte*)ptr); 28 } 29 void* malloc(size_t size, string file = __FILE__, size_t line = __LINE__) 30 { 31 auto nogc_malloc = cast(nogc_malloc_t)&rt.hooks.malloc; 32 return cast(void*)nogc_malloc(size, file, line).ptr; 33 } 34 void* calloc(size_t count, size_t size, string file = __FILE__, size_t line = __LINE__) 35 { 36 auto nogc_calloc = cast(nogc_calloc_t)&rt.hooks.calloc; 37 return cast(void*)nogc_calloc(count, size, file, line).ptr; 38 } 39 void* realloc(void* ptr, size_t size, string file = __FILE__, size_t line = __LINE__) 40 { 41 auto nogc_realloc = cast(nogc_realloc_t)&rt.hooks.realloc; 42 version(PSVita) 43 { 44 void* ret = cast(void*)nogc_realloc(cast(ubyte*)ptr, size, file, line).ptr; 45 free(ptr); 46 return ret; 47 } 48 else return cast(void*)nogc_realloc(cast(ubyte*)ptr, size, file, line).ptr; 49 } 50 } 51 void abort(){assert(false, "Aborted");} 52 } 53 else 54 { 55 extern(C) @nogc extern nothrow: 56 void free(void* ptr); 57 void* malloc(size_t size); 58 void* calloc(size_t count, size_t size); 59 void* realloc(void* ptr, size_t size); 60 } 61 version(WebAssembly) 62 { 63 void qsort(void* base, size_t nmemb, size_t size, _compare_fp_t compar){assert(false, "No sort implemented");} 64 void exit(int exitCode){assert(false, "Exit with code unknown");} 65 } 66 else 67 { 68 extern(C) @nogc extern nothrow: 69 void* memmove(void* str1, const(void)* str2, size_t n); 70 void exit(int exitCode); 71 void qsort(void *base, size_t nitems, size_t size, int function (void *, void*) compare); 72 int abs(int a){return a > 0 ? a : -a;} 73 74 @trusted 75 { 76 /// These two were added to Bionic in Lollipop. 77 int rand(); 78 /// 79 void srand(uint seed); 80 } 81 } 82